package com.hzcx.app.simplechat.util.system;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.alibaba.fastjson.JSONObject;
import com.hzcx.app.simplechat.MyApplication;
import com.hzcx.app.simplechat.util.log.LogUtils;


public class SystemUtils {

    //获取版本名
    public static String getVersionName() {
        return getPackageInfo().versionName;
    }

    //获取版本号
    public static int getVersionCode() {
        return getPackageInfo().versionCode;
    }

    //通过PackageInfo得到的想要启动的应用的包名
    private static PackageInfo getPackageInfo() {
        PackageInfo pInfo = null;

        try {
            //通过PackageManager可以得到PackageInfo
            PackageManager pManager = MyApplication.getContext().getPackageManager();
            pInfo = pManager.getPackageInfo(MyApplication.getContext().getPackageName(),
                    PackageManager.GET_CONFIGURATIONS);

            return pInfo;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return pInfo;
    }

    public static String getSystemJsonStr() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("mac", SystemMac.getMac());

        jsonObject.put("ipv4", IPV4Utils.getIpv4Address(MyApplication.getContext()));
        jsonObject.put("ipv6", GetIPv6Address.getLocalIpV6());

        try {
            jsonObject.put("imei", IMEI.getDeviceIMEI());
        } catch (Exception e) {
            LogUtils.e(e.getMessage());
        }

//        jsonObject.put("cpu_arch", CPU.getInfo());
        jsonObject.put("channel", "kiki");
        jsonObject.put("client_version", SystemUtils.getVersionName());
        jsonObject.put("platform", "android");
        jsonObject.put("application_id", MyApplication.getContext().getPackageName());

        return jsonObject.toJSONString();
    }
}
